package com.qst.crop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.crop.entity.Expert;
import com.qst.crop.dao.ExpertDao;
import com.qst.crop.service.ExpertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * (Expert)表服务实现类
 *
 * @author Wlj
 * @since 2025-09-02 15:28:32
 */
@Service
public class ExpertServiceImpl implements ExpertService {
    @Autowired
    private ExpertDao expertDao;

    //每页显示多条数据
    private Integer pageSize = 10;

    @Override
    public Expert selectById(String name) {

        Expert expert = expertDao.selectByPrimaryKey(name);

        return expert;
    }

    @Override
    public void insert(Expert expert) {
        expertDao.insertSelective(expert);

    }
    @Override
    public void updateById(Expert expert) {
        expertDao.updateByPrimaryKeySelective(expert);
    }
    @Override
    public List<Expert> selectAllExpert() {

        List<Expert> experts = expertDao.selectAllExpert();

        return experts;
    }

    @Override
    public PageInfo<Expert> findExpertPage(Integer pageNum) {
        PageHelper.startPage(pageNum == null || pageNum < 1 ? 1 : pageNum, 10);
        List<Expert> list = this.expertDao.selectAll();
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Expert> findExpertByKeys(String keys, Integer pageNum) {
        PageHelper.startPage(pageNum == null || pageNum < 1 ? 1 : pageNum, 10);
        String pattern = keys == null || keys.isEmpty() ? null : "%" + keys + "%";
        List<Expert> list = this.expertDao.selectByKeys(pattern);
        return new PageInfo<>(list);
    }

    @Override
    public Expert detail(String userName) {
        return this.expertDao.queryById(userName);
    }
    @Override
    public void delete(String name) {
        expertDao.deleteByPrimaryKey(name);
    }

}
